package com.sali.b_design_pattern.a_simple_factory_pattern.lesson_02.controller;


import com.sali.b_design_pattern.a_simple_factory_pattern.lesson_02.pojo.User;
import com.sali.b_design_pattern.a_simple_factory_pattern.lesson_02.service.order.IOrderService;
import com.sali.b_design_pattern.a_simple_factory_pattern.lesson_02.service.user.IFaUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description:
 * @date: 2022/11/13 18:17.
 * @version: 1.0
 */
@RestController
@Slf4j
public class OrderController {

    @Autowired
    private IFaUserService fauserService;
    @Autowired
    private IOrderService orderService;

    @PostMapping("/order/buy")
    public String buyCourse(@RequestParam("courseId") Long courseId) {
        // 实际从session或缓存中获取用户信息
        User user = fauserService.getUserById(1L);
        log.info("你购买的课程为：{}, 购买的用户：{}", courseId, user.getUsername());
        // 进行购买
        return orderService.buyCourse(user, courseId);
    }


}
